const KoaRouter = require('@koa/router')
const eventRouter = new KoaRouter({ prefix: '/event' })
const { verifyAuthorization } = require('../middleware/login.middleware')
const eventController = require('../controller/event.controller')
const { verifyAdminOnly } = require('../middleware/permission.middleware')
const {
	verifyRegister,
	verifyLimit,
	verifyNotRegister
} = require('../middleware/event.middleware')

// 1.创建活动
eventRouter.post('/', verifyAuthorization, eventController.create)

// 2.删除活动
eventRouter.delete('/:event_id', verifyAuthorization, eventController.remove)

// 3.修改活动
eventRouter.put('/:event_id', verifyAuthorization, eventController.update)

// 4.查找活动
eventRouter.get('/', eventController.search)

// 5.修改活动状态
eventRouter.put(
	'/:event_id/status',
	verifyAuthorization,
	verifyAdminOnly,
	eventController.updateStatus
)

// 6.根据id查询活动
eventRouter.get('/:event_id', eventController.searchEventById)

// 7.根据活动id查询参加活动的人员
eventRouter.get('/:event_id/member', eventController.searchEventMember)

// 8.报名活动
eventRouter.post(
	'/:event_id/member/:user_id/join',
	verifyAuthorization,
	verifyRegister,
	verifyLimit,
	eventController.joinEevent
)

// 9.取消报名
eventRouter.post(
	'/:event_id/member/:user_id/cancel',
	verifyAuthorization,
	verifyNotRegister,
	eventController.quitEvent
)
// 10.根据社团id查询活动
eventRouter.get('/:club_id/club', eventController.searchEventByClubId)

// 11.每个社团发布的活动个数
eventRouter.get('/club/count', eventController.searchPublishEventCount)
module.exports = eventRouter
